<template>
  <div class="app-container">
    <div class="switch" style="margin-bottom: 20px">
      <el-row>
        <el-col :span="4" :offset="2"><el-switch
          v-model="edit"
          active-text="编辑"
          inactive-text="预览"
        /></el-col>
      </el-row>
    </div>
    <div class="form">
      <el-form ref="form" label-width="200px" size="small">
        <el-form-item label="学生ID" size="medium">
          <el-col :span="8"><el-input v-model="form.studentId" :disabled="true" /></el-col>
        </el-form-item>
        <el-form-item label="姓名" size="medium">
          <el-col :span="8"><el-input v-model="form.studentName" :disabled="!edit" /></el-col>
        </el-form-item>

        <el-form-item label="性别" size="medium">
          <el-col :span="8"><el-select v-model="form.sex" placeholder="请选择">
            <el-option
              v-for="item in [{
                                value: 'man',
                                label: '男'
                              }, {
                                value: 'woman',
                                label: '女'
                              }]"
              :key="item.value"
              :label="item.label"
              :value="item.value"
              :disabled="!edit"
            />
          </el-select></el-col>
        </el-form-item>
        <el-form-item label="联系方式" size="medium">
          <el-col :span="8"><el-input v-model="form.telephone" :disabled="!edit" /></el-col>
        </el-form-item>
        <el-form-item label="地址" size="medium">
          <el-col :span="8"><el-input v-model="form.address" :disabled="!edit" /></el-col>
        </el-form-item>
        <el-form-item label="角色" size="medium">
          <el-col :span="8"><el-input v-model="form.roles" :disabled="!edit" /></el-col>
        </el-form-item>
        <el-form-item label="自我介绍">
          <el-col :span="12"><el-input v-model="form.introduction" size="medium" :disabled="!edit" /></el-col>
        </el-form-item>
        <el-form-item label="头像地址">
          <el-col :span="12"><el-input v-model="form.avatar" size="medium" :disabled="!edit" /></el-col>
        </el-form-item>
        <el-form-item label="job">
          <el-col :span="12"><el-input v-model="form.job" size="medium" :disabled="!edit" /></el-col>
        </el-form-item>
        <el-form-item label="组名">
          <el-col :span="12"><el-input v-model="form.sgroup" size="medium" :disabled="!edit" /></el-col>
        </el-form-item>
        <el-form-item label="班级">
          <el-col :span="12"><el-input v-model="form.sclass" size="medium" :disabled="!edit" /></el-col>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">立即创建</el-button>
          <el-button>取消</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div v-for="(value, name, index) in form" :key="index">
      {{ index }}. {{ name }}: {{ value }}
    </div>
    <span>{{ edit }}</span>

  </div>
</template>

<script>
import { saveStudent } from '@/api/student'
export default {
  data() {
    return {
      form: {
        studentId: '',
        studentName: '',
        sex: '',
        teleplone: '',
        address: '',
        roles: '',
        introduction: '',
        avatar: '',
        job: '',
        sgroup: '',
        sclass: ''
      },
      edit: false
    }
  },

  computed: {
  },
  watch: {
  },
  created() {
    this.form = this.$route.params
  },
  mounted() {
  },
  methods: {
    onSubmit() {
      saveStudent(this.form).then(() => {
        this.$message('submit success')
        this.$router.push({ path: '/student/student-all/' })
      }).catch(() => {
        this.$message('submit error')
      })
    }
  }
}
</script>
